home *** CD-ROM | disk | FTP | other *** search
- // TestGestalt.c
- //
- // simple test of Gestalt SAVC commands to control a screen saver
- //
-
- #include <Types.h>
- #include <Memory.h>
- #include <Quickdraw.h>
- #include <Fonts.h>
- #include <Events.h>
- #include <Menus.h>
- #include <Windows.h>
- #include <TextEdit.h>
- #include <Dialogs.h>
- #include <OSUtils.h>
- #include <ToolUtils.h>
- #include <SegLoad.h>
- #include <Sound.h>
-
- #include "TestGestalt.h"
-
- /* prototypes */
- void Initialize(void);
- void EventLoop(void);
- void DoTest(short item);
- void DoMouseDown(EventRecord *theEvent);
- void DoKeyDown(EventRecord *theEvent);
- void DoMenu(long menuResult);
-
- static Boolean gQuit = false;
-
- /*------------------------------------------------------------------------*/
- main(void)
- {
- Initialize();
- EventLoop();
- return 0;
- }
-
- /*------------------------------------------------------------------------*/
- void Initialize(void)
- {
- Handle theMBarHandle;
- MenuHandle theAppleMenu;
- DialogPtr theDialog;
-
- // Initialize toolbox managers.
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- // Set up the menus.
- theMBarHandle = GetNewMBar(MBAR_ID);
- SetMenuBar(theMBarHandle);
- theAppleMenu = GetMenuHandle(APPLE_ID);
- AppendResMenu(theAppleMenu, 'DRVR');
- DrawMenuBar();
-
- // Put up our dialog.
- theDialog = GetNewDialog(TEST_DLOG, nil, (WindowRef) -1L);
- }
-
- /*------------------------------------------------------------------------*/
- void EventLoop(void)
- {
- EventRecord event;
- Boolean gotEvent;
- short item = 0;
- DialogPtr dp;
-
- while (!gQuit)
- {
- gotEvent = WaitNextEvent(everyEvent, &event, 0L, nil);
- if (gotEvent) {
- if (IsDialogEvent(&event)) {
- if (DialogSelect(&event, &dp, &item))
- if (item == QUIT_BTN)
- gQuit = true; // Quit button was pressed
- else
- DoTest(item);
- }
- switch (event.what) {
- case mouseDown:
- DoMouseDown(&event);
- break;
- case keyDown:
- case autoKey:
- DoKeyDown(&event);
- break;
- }
- }
- }
- }
-
- /*------------------------------------------------------------------------*/
- void DoTest(short item)
- {
- // call Gestalt to get the control procedure pointer
- SaverControlUPP theControlProc;
- OSErr theErr = Gestalt(gestaltScreenSaverControl, (long*)&theControlProc);
- if (theErr != noErr)
- return;
-
- switch (item) {
- case SLEEP_BTN: { // Sleep
- // call the control procedure with the "sleep now" command
- CallSaverControlProc(theControlProc, gestaltSaverSleep);
- break;
- }
- case DSLEEP_BTN: { // Deep Sleep
- unsigned long wakeTime = TickCount() + (5*60);
-
- // put the screen saver into "deep sleep" mode
- CallSaverControlProc(theControlProc, gestaltSaverDeepSleep);
-
- // wait 5 seconds, then wake it up
- while (TickCount() < wakeTime) {
- EventRecord dummyEvt;
- (void) WaitNextEvent(nullEvent, &dummyEvt, 0L, nil);
- }
- CallSaverControlProc(theControlProc, gestaltSaverWakeUp);
- break;
- }
- case OFF_BTN: { // Turn Off
- // call the control procedure with the "off" command
- CallSaverControlProc(theControlProc, gestaltSaverOff);
- break;
- }
- case ON_BTN: { // Turn On
- // call the control procedure with the "on" command
- CallSaverControlProc(theControlProc, gestaltSaverOn);
- break;
- }
- }
- }
-
- /*------------------------------------------------------------------------*/
- void DoMouseDown(EventRecord *theEvent)
- {
- register short code;
- WindowPtr whichWindow;
- RgnHandle boundsRgn;
- long newSize;
-
- boundsRgn = GetGrayRgn();
- code = FindWindow(theEvent->where, &whichWindow);
-
- switch (code) {
- case inMenuBar:
- DoMenu(MenuSelect(theEvent->where));
- break;
- case inSysWindow:
- SystemClick(theEvent, whichWindow);
- break;
- case inContent:
- if (whichWindow != FrontWindow())
- SelectWindow(whichWindow);
- break;
- case inDrag:
- DragWindow(whichWindow, theEvent->where, &(*boundsRgn)->rgnBBox);
- break;
- case inGrow:
- newSize = GrowWindow(whichWindow, theEvent->where, &(*boundsRgn)->rgnBBox);
- if (newSize)
- {
- SetPort(whichWindow);
- EraseRect(&whichWindow->portRect);
- SizeWindow(whichWindow, LoWord(newSize), HiWord(newSize), true);
- InvalRect(&whichWindow->portRect); /* erase scroll bar marks */
- }
- break;
- case inGoAway:
- if (TrackGoAway(whichWindow, theEvent->where))
- DisposeWindow(whichWindow);
- break;
- case inZoomIn:
- case inZoomOut:
- if (TrackBox(whichWindow, theEvent->where, code))
- {
- SetPort(whichWindow);
- EraseRect(&whichWindow->portRect);
- ZoomWindow(whichWindow, code, TRUE);
- InvalRect(&whichWindow->portRect); /* erase scroll bar marks */
- }
- break;
- }
- }
-
- /*------------------------------------------------------------------------*/
- void DoKeyDown(EventRecord *theEvent)
- {
- register short c;
-
- c = (unsigned char)(theEvent->message & charCodeMask);
- if (theEvent->modifiers & cmdKey)
- DoMenu(MenuKey(c));
- }
-
- /*------------------------------------------------------------------------*/
- void DoMenu(long menuResult)
- {
- short menuID, itemNumber;
- Str255 daName;
- GrafPtr oldPort;
-
- menuID = HiWord(menuResult);
- itemNumber = LoWord(menuResult);
-
- switch (menuID) {
- case APPLE_ID:
- if (itemNumber != ABOUT_ITEM)
- {
- GetMenuItemText((MenuRef)GetMenuHandle(APPLE_ID), itemNumber, daName);
- GetPort(&oldPort);
- OpenDeskAcc(daName);
- SetPort(oldPort);
- }
- break;
- case FILE_ID:
- if (itemNumber == QUIT_ITEM)
- gQuit = true;
- break;
- case EDIT_ID:
- if (itemNumber <= CLEAR_ITEM)
- SystemEdit(itemNumber-1);
- break;
- default:
- break;
- }
- HiliteMenu(0);
- }
-
-
-
-